package com.bite.HappyNumber;

public class Demo {
    //快慢指针
    public boolean isHappy(int n) {
        int slow = n;
        int fast = Squaredsum(n);
        while (slow != fast) {
            slow = Squaredsum(slow);
            fast = Squaredsum(Squaredsum(fast));
        }
        return slow == 1;
    }
    //计算平方和
    public int Squaredsum(int value) {
        int sum = 0;
        while (value != 0) {
            sum += Math.pow((value % 10),2);
            value /= 10;
        }
        return sum;
    }

}
